# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   selenium_self
# FileName:      read_ini.py
# Author:       test_liu
# Datetime:     2024/8/15 上午10:57
# Description:
# ---------------------------------------------------------------------------
import os
from configparser import ConfigParser


class ReadIni:
    def __init__(self):
        # 该py文件路径
        now_path = __file__
        # 父级目录
        py_dir = os.path.dirname(now_path)
        # 父级的父级目录
        py_dirs = os.path.dirname(py_dir)
        # 获取config_data文件路径
        self.config_data = os.path.join(py_dirs, 'config_data')
        # 获取report文件路径
        self.report_data = os.path.join(py_dirs, 'report')
        # 获取ini文件路径
        self.ini_path = os.path.join(self.config_data, 'config.ini')
        # 创建对象
        self.config = ConfigParser()
        self.config.read(self.ini_path, encoding='utf-8')

    # 获取数据库信息
    def get_sql_connect(self, key):
        return self.config.get('sql', key)

    # 获取文件路径[file中的目录路径]
    def get_file_path(self, key):
        file_path = os.path.join(self.report_data, self.config.get('file', key))
        return file_path

    # 获取excel文件路径
    def get_excel(self, key):
        excel_path = os.path.join(self.config_data, self.config.get('excel', key))
        return excel_path

    def get_table(self, key):
        return self.config.get('table', key)

if __name__ == '__main__':
    ini = ReadIni()
    print(ini.get_file_path('img'))
    print(ini.get_excel('excel'))
    print(ini.get_table('login'))